/**
 * 
 */
package com.curso.sesion10;

import java.io.File;


public class FileNavigator {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String treeRoot = "E:\\peter\\CursoJava";
		if (args.length > 0) {
			treeRoot = args[0];
		}
		
		File rootDir = new File(treeRoot);
		System.out.println("Root of navigation:"+rootDir.getAbsolutePath());
		
		if(!rootDir.isDirectory()) {
			System.out.println("The root of the navigation subtree does not exist as a directory");
			System.exit(0);
		}
		
		FileNavigator fn = new FileNavigator();
		fn.navigate(rootDir);

	}
	
	public void navigate(File dir) {
		System.out.println(" ");
		System.out.println("Durectory "+ dir + ":");
		String[] dirContent = dir.list();
		for (int i = 0; i < dirContent.length; i++) {
			System.out.println(" "+dirContent[i]);
			File child = new File(dir, dirContent[i]);
			if (child.isDirectory()) {
				navigate(child);
			}
		}
	}
	

}
